package study.itheima.stusys;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/Stulist")
public class Stulist extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("Text/Html;charset=UTF-8");
        String realPath = getServletContext().getRealPath("/WEB-INF/classes/stu.txt");
        BufferedReader br = new BufferedReader(new FileReader(realPath));
        PrintWriter pw = resp.getWriter();
        String s;
        while ((s = br.readLine())!= null){
            pw.write(s);
            pw.write("<br/>");
        }
        pw.close();
        br.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
